package com.yanqu.road.server.manager.activity.hsisland.handler.impl;

import com.yanqu.road.entity.activity.hsisland.HsIslandExploreResult;
import com.yanqu.road.entity.activity.hsisland.HsIslandReward;
import com.yanqu.road.entity.activity.hsisland.HsIslandUnionLog;
import com.yanqu.road.entity.activity.hsisland.config.HsIslandConfig;
import com.yanqu.road.entity.activity.hsisland.data.HsIslandEventData;
import com.yanqu.road.entity.activity.hsisland.data.HsIslandMonsterData;
import com.yanqu.road.entity.activity.hsisland.enums.HsIslandMonsterTypeEnum;
import com.yanqu.road.entity.activity.hsisland.enums.HsIslandUnionLogTypeEnum;
import com.yanqu.road.server.manager.activity.hsisland.*;
import com.yanqu.road.server.manager.activity.hsisland.handler.param.HsIslandExploreHandlerReq;
import com.yanqu.road.server.manager.activity.hsisland.handler.param.HsIslandExploreHandlerResp;
import com.yanqu.road.server.manager.activity.hsisland.handler.HsIslandIEventHandler;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class HsIslandEventKeyHandler implements HsIslandIEventHandler {

    /**
     * 探索后处理
     * @param req
     * @return
     */
    @Override
    public HsIslandExploreResult explore(HsIslandExploreHandlerReq req) {
        CrossHsIslandActivity activity = req.getActivity();
        HsIslandConfig config = activity.getConfig();
        HsIslandEventData eventData = req.getEventData();
        CrossHsIslandIsland island = req.getIsland();
        CrossHsIslandUser user = req.getUser();
        CrossHsIslandFloor floor = req.getFloor();
        CrossHsIslandUnion union = req.getUnion();
        //事件注入坐标
        eventData.addPosition(req.getX(), req.getY());
        //注入事件
        island.putEvent(eventData);
        //加上海神之心
        island.addKeyNum();
        //积分
        long score = config.HSISLAND_KEY_GET_SCORE;
        //奖励
        HsIslandReward hsIslandReward = user.createReward(score, null, null, eventData);
        //【海神之心】事件探索完就完结
        island.finishEvent(eventData);
        //判断海神之心是否集齐
        if (floor.getKeyNum() >= 3) {
            //更新最高海域
            union.updateMaxFloor();
        } else {
            //海神之心未集齐,推送跑马灯
            floor.syncMarqueeKeyMsg(floor.getKeyNum());
        }
        //商会日志-有人发现【海神之心】
        HsIslandUnionLog unionLog = new HsIslandUnionLog();
        unionLog.setType(HsIslandUnionLogTypeEnum.UNION_LOG_TYPE_4.getType());
        unionLog.setUserId(user.getUserData().getUserId());
        unionLog.setFloor(floor.getFloorData().getFloorId());
        unionLog.setKeyNum(floor.getKeyNum());
        unionLog.setTime(System.currentTimeMillis());
        union.addUnionLog(unionLog);
        //返回
        HsIslandExploreResult resp = new HsIslandExploreResult();
        resp.addEventData(eventData);
        resp.setReward(hsIslandReward);
        return resp;
    }
}
